package simpleftp.client.control;

import java.io.File;
import java.util.concurrent.Callable;
import simpleftp.client.gui.FTPClientWindow;


//---Class Downloader based on the class Uploader
//-----------------------------------------------
public final class Downloader implements Callable<Boolean> 
{
	private SimpleFTP client;
	private String server;
	private String port;
	private FTPClientWindow wind;
	private String user;
	private String pass;
	private File file;

	public Downloader(File f, FTPClientWindow window, String server, String port, String user, String pass)
	{
		this.file = f;
		this.server = server;
		this.port = port;
		this.wind = window;
		this.user = user;
		this.pass = pass;
		client = new SimpleFTP();
	}

	@Override
	public Boolean call() throws Exception
	{
		System.out.println("DOWNLOAD starting for " + file.getName());
		Boolean result = false;
		client.connect(server, Integer.parseInt(port), user, pass);
		result = client.retr(file);
		if (result) {
			wind.console.append("File successfully retrieved "
					+ file.getName());
			System.out.println("File successfully retrieved "
					+ file.getName());
			
		} else {
			wind.console.append("Failed retrieving the file " + file.getName());
			System.out.println("Successfully retrieved file "
					+ file.getName());
		}
		return result;
	}
}
